import { Context } from 'koa';
import svgCaptcha from 'svg-captcha';

export default async (ctx: Context, next) => {
    if (ctx.path === '/captcha') {
        const captcha = svgCaptcha.create({
            fontSize: 48,
            noise: 3,
            width: 100,
            height: 100,
            size: 4,
            ignoreChars: '0o1i',
        })
        ctx.session.captcha = captcha.text.toLocaleLowerCase();
        ctx.set('Content-Type', 'image/svg+xml');
        ctx.body = captcha.data;
    } else {
        return await next();
    }
}